 

import java.util.ArrayList;

/**
 * Container class for Products
 * @author Stefan
 */
public class ProductContainer
{
    //Attributes

    private ArrayList<Product> products;
    private static ProductContainer instance = new ProductContainer();

    private ProductContainer()
    {
        products = new ArrayList<Product>();
    }

    /**
     * Singleton
     * @return Instance of ProductContainer
     */
    public static ProductContainer getInstance()
    {
        return instance;
    }

    /**
     * 
     * @param product
     * @return false if Id already exists else true
     */
    public boolean addProduct(Product product)
    {
        boolean testID = true;
        for (Product pro : products)
        {
            if (pro.getId().equals(product.getId()))
            {
                testID = false;
            }
        }
        if (testID == true)
        {
            products.add(product);
        }
        return testID;
    }

    public void clearProducts()
    {
        products.clear();
    }

    public int getSize()
    {
        return products.size();
    }

    /**
     *
     * @param ID
     * @return Product or null (if not found)
     */
    public Product findProduct(String ID)
    {
        Product found = null;
        for (Product pro : products)
        {
            if (pro.getId().equals(ID))
            {
                found = pro;
            }
        }
        return found;
    }

    public void deleteProduct(Product prod)
    {
        products.remove(prod);
    }
}
